package com.wxzl.community.common.utils.ext

import java.util.regex.Matcher
import java.util.regex.Pattern

/**
 * @Author: LiaoZhongKai
 * @Date: 2021/5/8 16:41
 * @Description:
 */

/**
 * 是否包含特殊符号
 */
fun String.hasSpecialSymbols(): Boolean {
    val speChat = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]";
    val pattern = Pattern.compile(speChat)
    val matcher = pattern.matcher(this);
    return matcher.find()
}

/**
 * 邮箱格式是否正确
 */
fun String.isEmail(): Boolean{
    if (this.isEmpty()) return false
    //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
    //Pattern p = Pattern.compile("\\w+@(\\w+.)+[a-z]{2,3}"); //简单匹配
    val p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*") //复杂匹配
    val m: Matcher = p.matcher(this)
    return m.matches()
}